import service, { get, post } from '@/utils/request';
import qs from 'qs'
const servletMap = [
	// [ '/web/research/exam/getSubjects', 'getSubjects','post' ],
	// [ '/web/research/exam/getExamBankList', 'getExamBankList','post' ],
	// [ '/web/research/exam/getExamBookKnowledgeList', 'getExamBookKnowledgeList','post' ],

	// 提交试卷
	[ '/exam/records/submit-paper-answer', 'submitPaper','post' ],
	[ '/exam/records/save-paper-answer', 'savePaper','post' ],
	// 保存试卷章节练习模式记录
	// [ '/exam/records/save-practice-record', 'savePractice' ,'post'],
	// 保存章集合统计数据
	[ '/exam/records/save-chapter-records', 'saveChapter','post' ],

	// 提交单个试题做题记录，适用于我的错题重做，我的收藏，高频错题做题
	[ '/exam/records/push-question-answer', 'pushQuestion','post' ],
	// 集合做题退出时保存收藏数据
	[ '/exam/records/push-new-collect', 'pushCollect','post' ],
	// 集合做题退出时保存错题数据
	[ '/exam/records/push-collect-error-answer', 'pushError','post' ],
	// 练习模式退出时提交答案
	[ '/exam/records/push-chapter-answer', 'pushChapter','post' ],
	// 未登录交卷试卷交卷
	[ '/exam/records/public-submit-paper-answer', 'publicSubmit','post' ],
	// 获取错题试题集合
	[ '/exam/records/error-collection', 'errorCollection','post' ],

	// 获取用户累计做题
	[ '/exam/records/user-count-records', 'userCountRecords', 'get' ],

	// 获取集合的收藏记录
	[ '/exam/records/collection-collect-records', 'getCollectRecords', 'get' ],
	// 获取集合的做题记录
	[ '/exam/records/collect-question-records', 'getDoneQuestion', 'get' ],
	// 获取章节的做题数统计
	[ '/exam/records/chapter-records', 'getChapterRecords', 'get' ],
	// 获取集合试题的做题记录归类
	[ '/exam/records/chapter-records-tree', 'getChapterRecordsTree', 'get' ],
	
	// 获取科目下做题数据
	[ '/exam/records/category-records', 'getCategoryRecords', 'get' ],
	// 获取考试或者科目下做题排做题
	[ '/exam/records/category-rank', 'getCategoryRank', 'get' ],
	// 获取考试或者科目下错题排行
	[ '/exam/records/category-rank-error', 'getCategoryRankError', 'get' ],
	// 获取考试或者科目下错题排行
	[ '/exam/records/category-rank-error-kaoyan', 'getCategoryRankErrorKaoyan', 'get' ],
	// 获取考试或者科目下错题排行
	[ '/exam/records/category-rank-error-kaoyan-type', 'getCategoryRankErrorKaoyanType', 'get' ],
	// 获取考试或者科目下收藏排行
	[ '/exam/records/category-rank-collect', 'getCategoryRankCollect', 'get' ],
	// 获取科目下最新错题
	[ '/exam/records/category-news-error', 'getCategoryNewsError', 'get' ],
	// 获取科目下最新收藏
	[ '/exam/records/category-news-collect', 'getCategoryNewsCollect', 'get' ],
	// 获取科目下的集合做题记录
	[ '/exam/records/category-collect-records', 'getCategoryCollectRecords', 'get' ],

	['/exam/exam/submit-suggestion','submitSuggestion','post'],
	['/user/sys/hot-question/page','getHotQuestion','get'],
	["/exam/week-rank/index","getWeekRank","get"]
];
let obj = {};
for (let i in servletMap) {
	obj[servletMap[i][1]] = function() {
		return service[servletMap[i][2]](servletMap[i][0],...arguments)
	};
}

export default {
	...obj,
	collectQuestion(data) {
		return post('/exam/records/push-question-collect', data);
	},
	// 获取试卷收藏
	paperRecordsCollect(config) {
		return get('/exam/records/paperRecordsCollect', config);
	},
	// 获取收藏试题集合
	collectionCollect(data) {
		// /exam/records/collect-collection-new
		return post('/exam/records/collect-collection', data,);
	},
	// ??? 
	// questionCheck(data) {
	// 	return post('/exam/records/push-question-right-check', data, {
	// 		headers: {
	// 			'encryption-type': 'aes'
	// 		}
	// 	});
	// },
	questionCheck(data) {
		return post('/exam/records/push-question-right-check', null, {
			params: data,
			headers: {
				'encryption-type': 'aes',
			},
			paramsSerializer:(params)=>qs.stringify(params, {arrayFormat: 'brackets'})
		});
	},
	
	// 删除单个错题记录
	delError(data) {
		return service.delete('/exam/records/del-one-error');
	},
	// 删除单个收藏记录
	delCollect(params) {
        // console.log(params);
		return service.delete('/exam/records/del-one-collect',{
            params
        });
	},
	// 删除试题集合 收藏记录 或者 错题记录
	delChapterCollect(data) {
		return service.delete('/exam/records/del-chapter-collect');
	},
	// 删除科目错题记录
	delCategoryError(data) {
		return service.delete('/exam/records/del-category-error');
	},
	// 删除科目收藏记录
	delCategoryCollect(data) {
		return service.delete('/exam/records/del-category-collect');
	},
	// 清空试卷记录
	cleanPaperRecords(id) {
		return service.delete('/exam/records/clean-paper-records/' + id);
	},
	// 删除集合做题/错题记录
	cleanCollectRecords(id,config) {
		return service.delete('/exam/records/clean-collect-records/' + id,config);
	},
	// 删除科目所有记录
	cleanCategory() {
		return service.delete('/exam/records/clean-category');
	},
	// 删除集合做题/错题记录
	cleanCategoryQuestionRecords() {
		return service.delete('/exam/records/clean-category-question-records');
	},

	// 获取章节的做题数统计-章节ids集合
	// [ '/exam/records/chapter-records-ids', 'getChapterRecordsIds', 'get' ],
	getChapterRecordsIds(config){
		return service.get('/exam/records/chapter-records-ids',config);
	}
};
